package com.study.lxy.springcloud.common.format;

import com.study.lxy.springcloud.common.constance.CommonRespEnum;
import com.study.lxy.springcloud.common.exception.ErrorMsg;

public class ServiceResp {

    private String errorCode;
    private String errorMsg;
    private Object respData;

    public String getErrorCode() {
        return errorCode;
    }
    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Object getRespData() {
        return respData;
    }

    public void setRespData(Object respData) {
        this.respData = respData;
    }
    public static ServiceResp fail(String code,String message){
        ServiceResp serviceResp = new ServiceResp();
        serviceResp.setErrorCode(code);
        serviceResp.setErrorMsg(message);
        return serviceResp;
    }

    public static ServiceResp fail(ErrorMsg errorMsg){
        ServiceResp serviceResp = new ServiceResp();
        serviceResp.setErrorCode(errorMsg.getCode());
        serviceResp.setErrorMsg(errorMsg.getMessage());
        return serviceResp;
    }

    public static ServiceResp buildResult(Object data){
        ServiceResp serviceResp = new ServiceResp();
        serviceResp.setErrorCode(CommonRespEnum.SUCCESS.getCode());
        serviceResp.setErrorMsg(CommonRespEnum.SUCCESS.getMessage());
        serviceResp.setRespData(data);
        return serviceResp;
    }

    public static ServiceResp dummyResp(){
        return ServiceResp.buildResult(null);
    }
}
